  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>运营平台</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.5 -->
  <link rel="stylesheet" href="/customer_plat/public/bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/customer_plat/public/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="/customer_plat/public/css/ionicons.min.css">
 
  <!--date-->
   <link rel="stylesheet" href="/customer_plat/public/datepicker/bootstrap-datepicker.min.css">
  
  <!-- Theme style -->
  <link rel="stylesheet" href="/customer_plat/public/dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="/customer_plat/public/dist/css/skins/_all-skins.min.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  
  <!--plugins-->
  <link rel="stylesheet" href="/customer_plat/public/plugins/datatables/dataTables.bootstrap.css">
  <!--[if lt IE 9]>
  <script src="/customer_plat/public/javascripts/html5shiv.min.js"></script>
  <script src="/customer_plat/public/javascripts/respond.min.js"></script>
  <![endif]-->
<script src="/customer_plat/public/plugins/jQuery/jquery-1.12.0.min.js"></script>
<script src="/customer_plat/public/layer/layer.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="/customer_plat/public/bootstrap/js/bootstrap.min.js"></script>
<script src="/customer_plat/public/bootstrap/js/bootstrap3-validation.js"></script>
<!--cityselect  -->
<script src="/customer_plat/public/javascripts/city/jquery.cityselect.js"></script>
<!-- AdminLTE App -->
<script src="/customer_plat/public/dist/js/app.js"></script>
<script src="/customer_plat/public/plugins/json2.js"></script>
<!--plugins-->
<script src="/customer_plat/public/plugins/datatables/jquery.dataTables.js"></script>
<script src="/customer_plat/public/plugins/datatables/dataTables.bootstrap.min.js"></script>

<script src="/customer_plat/public/plugins/jQueryUI/jquery-ui.js"></script>
<link rel="stylesheet" href="/customer_plat/public/plugins/jQueryUI/jquery-ui.css">
<script src="/customer_plat/public/datepicker/bootstrap-datepicker.min.js"></script>
<script src="/customer_plat/public/datepicker/bootstrap-datepicker.zh-CN.min.js"></script>
<!-- SlimScroll -->
<script src="/customer_plat/public/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="/customer_plat/public/plugins/fastclick/fastclick.js"></script>
<script src="/customer_plat/public/select2/select2.min.js"></script>
<link rel="stylesheet" href="/customer_plat/public/select2/select2.min.css">
<section class="content-header">
	<h1>
		<small></small>
	</h1>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
			
				<div class="box-header  with-border">
					<h3 class="box-title">刀具列表</h3>
				</div>
				<div class="row box-header">
					<input type="hidden" id="supplierId" value="${supplierId}">
										<input type="hidden" id="supp_name" value="${supp_name}">
					
					<div class="col-md-3">
						<div class="input-group">
							<span class="input-group-addon"> <label>关键字</label>
							</span> <input type="text" class="form-control" id="name" />
						</div>
					</div>
					<div class="">
						<button type="button" class="btn btn-primary pull-left"
							onclick="mill_load()">查询</button>
					</div>
							<div class="col-md-2">
						<a href="#myModal" style="width: 61.12;height: 39.11;line-height: 36px;" class="btn btn-primary btn-xs p310" data-toggle="modal">
                                        <i class="im-plus"></i>
                                        创建
                                    </a>
					</div>
				</div>

				<!--/.box-header -->
				<div class="box-body">
					<table id="mill_list"
						class="table table-striped table-bordered table-hover dataTables-example dataTable no-footer">
						<thead>
						</thead>
						<tbody>
						</tbody>
						<tfoot>

						</tfoot>
					</table>
				</div>
				<!-- /.box-body -->
			</div>
		</div>
	</div>

<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModelLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                    aria-label="Close" id="colseBtn">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h3 id="myModalLabel">刀具信息</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="resMillForm">
                    <div class="box-body-add">
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="supplierMaterialCode">供应商物料编码:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="supplierMaterialCode" palceholder="name" />
                            </div>
                            <span class="help-block">选填</span>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="longName">供应商规格:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="longName" palceholder="name" check-type="required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="shortName">供应商规格简称:</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="shortName" palceholder="name" check-type="required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="supplierDesc">供应商描述:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="supplierDesc" palceholder="name"/>
                            </div>
                        </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label" for="safeQty">客户安全库存:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="safeQty" check-type="number" required-message="必填" palceholder="name"/>
                            </div>
                        </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label" for="customerMaterialCode">客户物料编码:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="customerMaterialCode" check-type="required" required-message="必填" palceholder="name"/>
                            </div>
                        </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label" for="customerLongName">客户物料规格:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="customerLongName" check-type="required" required-message="必填" palceholder="name"/>
                            </div>
                        </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label" for="customerShortName">客户物料简称:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="customerShortName" check-type="required" required-message="必填" palceholder="name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="millDNType">刀具直径类型:</label> 
                            <div class="col-sm-6">
                                <select class="form-control" id="millDNType"check-type="required" required-message="必填" onchange="selectchange(this)";> 

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="millType">刀具类型:</label> 
                            <div class="col-sm-6">
                                <select class="form-control" id="millType"check-type="required" required-message="必填" onchange="selectchange(this)";> 

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                              <span id="error-text" style="color: #FF0000;font-size: 2em"></span>
                            </div>
                          </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary" id="btnMillAdd">保存</button>
                <button class="btn btn-danger" data-dismiss="modal"
                    aria-hidden="true">取消
                </button>
            </div>
        </div>
    </div>
</div>
<div id="editModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModelLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                    aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h3 id="myModalLabel">修改订单信息</h3>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="editForm">
                    <div  id="editMillBody">
                        <div class="form-group" hidden="true">
                            <label class="col-sm-3 control-label" for="millId">刀具id:</label> 
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="millId" palceholder="name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="supplierMaterialCode">物料编码:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="supplierMaterialCode" palceholder="name"check-type="required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="longName">规格:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="longName" palceholder="name"check-type="required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="shortName">规格简称:</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="shortName" palceholder="name"check-type="required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="supplierDesc">描述:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="supplierDesc" palceholder="name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="editMillDNType">刀具直径类型:</label> 
                            <div class="col-sm-6">
                                <select class="form-control" id="editMillDNType"check-type="required" required-message="必填" onchange="selectchange(this)";> 

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="editMillType">刀具类型:</label> 
                            <div class="col-sm-6">
                                <select class="form-control" id="editMillType"check-type="required" required-message="必填" ;> 

                                </select>
                            </div>
                        </div>
                        <!-- <div class="form-group">
                            <label class="col-sm-2 control-label" for="slotsNumber">槽数:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="slotsNumber" palceholder="name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="origin">产地:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="origin" palceholder="name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="helicalAngle">螺旋角:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="helicalAngle" palceholder="name"check-type="number required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="diameter">刀径:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="diameter" palceholder="name"check-type="number required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="length">刀具长:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="length" palceholder="name" check-type="required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="shk">柄径:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="shk" palceholder="name" check-type="required" required-message="必填"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="fluteLength">槽长:</label> 
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="fluteLength" palceholder="name" check-type="required" required-message="必填"/>
                            </div>
                        </div> -->
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                              <span id="error-edit-text" style="color: #FF0000;font-size: 2em"></span>
                            </div>
                          </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" id="btnEditMill">
                确定</button>
                <button class="btn btn-danger" id="closeEditBtn" data-dismiss="modal" aria-hidden="true">取消
                </button>
            </div>
        </div>
    </div>
</div>

</section>
<style type="text/css">
.selected {
	background-color: #abb9d3 !important;
}
</style>
<script>
	$("#resMillForm").validation();
	var param = {};
	var millTable = null;
	$(function() {
		millTable = $('#mill_list')
				.DataTable(
						{
							"columns" : [ {
								"title" : "详情",
								"data" : null
							},{
								"title" : "供应商名称",
								"data" : "supplierLongName"
							}, {
								"title" : "供应商物料编码",
								"data" : "supplierMaterialCode"
							}, {
								"title" : "简称",
								"data" : "shortName"
							}, {
								"title" : "规格",
								"data" : "longName"
							},{
								"title" : "刀具类型",
								"data" : "millType" 
							},
							{
								"title" : "刀具描述",
								"data" : "supplierDesc"
							},{
								"title" : "状态",
								"data" : "status"
							}],
							"paging" : true,
							"lengthChange" : false,
							"searching" : false,
							"ordering" : false,
							"info" : true,
							"autoWidth" : false,
							"language" : {
								"emptyTable" : '没有数据',
								"paginate" : {
									"previous" : '上一页',
									"next" : '下一页'
								},
								"info" : "第 _START_条到 _END_ 条，共 _TOTAL_ 条",
								"sInfoEmpty" : "第 0 条到 0 条结果，共 0 项"
							},
							"serverSide" : true,
							"processing" : true,
							"ajax" : {
								"url" : "@{supplier.SupplierManageAction.getSupplierCutterList}?supplierId="+$("#supplierId").val(),
								"type" : "POST",
								"data" : function(d) {
									//添加额外的参数传给服务器
									d.extra_search = supplier_serverParams();
								}
							},"columnDefs": [{
											    "targets": [ 0 ],
											    "render": function ( data, type, full ) {
											    	return '<button type="button" class="btn btn-box-tool fa fa-plus" id="open"></button>';
											    }
											  },{
										           "targets": [ 7 ],
										           "render": function ( data, type, full ) {
										        	   if(data == 0){
										        		   return "新建";
										        	   }else if(data == 1){
										        		   return "发布";
										        	   }else if(data == 2){
										        		   return "下架";
										        	   }else if(data == 3){
										        		   return "审核通过";
										        	   }else if(data == 4){
										        		   return "审核不通过";
										        	   }else{
										        		   return data;
										        	   }
										           }
										         } 
											  ]
							
						});
		

	     //保存按钮
	    $('#btnMillAdd').click(function(){
	    	$("#btnMillAdd").attr("disabled","true");
	        //$("#resMillForm").
	         if ($("#resMillForm").valid()==false){
	            $("#error-text").text("请输入必填项!");
	            return false;
	         }
	        param.supplierId=$("#supplierId").val();
	        param.supp_name=$("#supp_name").val();
	        console.log($("#resMillForm input"))
	        var typeJson={};
	        $.each($("#resMillForm input"),function(i,item){
	            var value=item.value;
	            var key=item.id
	            if (i>7){
	                typeJson[key]=item.value;
	            }else{
	                param[key]=item.value;
	            }          
	        });
	        param.millType = $("#millDNType").val();
	        param["typeJson"]=JSON.stringify(typeJson)
	        $.post("addMill",param,function(data){
	        	console.log(data)
	        	if(data.ret==1000){
	        		alert("添加成功!!");
	        		location.reload();
	        	}else{
	        		alert(data.msg);
 	    	    	 $("#btnMillAdd").removeAttr("disabled");//将按钮可用

	        	}
	        	
	        });
	    });
	     $('#btnSearch').click(function(){
	        oTable.ajax.reload();
	        //para.customerId=$("#custId").val();
	       //apiCall("get", "mill/listbycustid", para, showMillListBycustId)
	    })

		
		
	});
	function supplier_serverParams() {
		var status = $("#status").val();
		var name=$("#name").val();
		
		var params = {
			"status" : status,
			"name":name
		
		};
		return params;
	}
	
	function mill_load(){
		millTable.ajax.reload();
	}
	
	// 弹出状态修改框
/* 	function edit_status(data){
		var array=data.split("|");
		$("#editStatusForm").validation();
		$('#editStatusForm')[0].reset();
		//填充内容 
		$("#up_id").val(array[0]);
		// 		$("#msmkShortName").val(array[1]);
		$("#msmkLongName").val(array[2]);
		$("#msmkDesc").val(array[3]);
		$("#msmkMaterialCode").val(array[4]);
		//显示弹出框
		$("#msmkAudit").show();
		$("#editStatusModal").modal('show');
	}
	// 提交状态修改
	function saveStatus(){
		 if ($("#editStatusForm").valid(this)==false){
		        return
		    }else{
		var id = $("#up_id").val();
		var status = $("#up_status").val();
		var msmkShortName = $("#msmkShortName").val();
		var msmkLongName = $("#msmkLongName").val();
		var msmkDesc = $("#msmkDesc").val();
		var msmkMaterialCode=$("#msmkMaterialCode").val();
		var params = {
				"millId" : id,
				"status" : status,
				"msmkShortName" : msmkShortName,
				"msmkLongName" : msmkLongName,
				"msmkDesc" : msmkDesc,
				"msmkMaterialCode":msmkMaterialCode
			}
		$.ajax({
			type : "POST",
 			data : params,
			success : function(msg) {
				if (msg.status == '201') {
					showMsg("修改状态", "关闭", "确定", "保存成功");
					$("#editStatusModal").modal('hide');
					millTable.ajax.reload();
				}else{
					$("#editStatusModal").modal('hide');
					showMsg("修改状态", "关闭", "确定", "保存失败");
				}
			}
		});
		}
	}
	**/
	
	// 查看刀具详细信息
	$('#mill_list tbody').on('click', '#open', function () {
        var tr = $(this).closest('tr');
        var button = $(this).closest('tr td button');
        var row = millTable.row( tr );
        
        if(button.hasClass('fa-plus')){
            button.removeClass('fa-plus');
            button.addClass('fa-minus');
            row.child( formatData(row.data()) ).show();
        }else{
        	button.removeClass('fa-minus');
            button.addClass('fa-plus');
            row.child.hide();
        }
       
    } );
	
	$(function() {
		lookUpList();
		showMillTypeList();
		showLookUpList();
		//查询币种
	});
	var LookUpList = null;
	function lookUpList() {
		var par = {
			"typesupplier" : "typesupplier"
		};
		$.ajax({
			type : "POST",
			url : "@{supplier.SupplierManageAction.getTypeSupplier}",
			data : par,
			async: false,
			success : function(msg) {
				LookUpList = $.parseJSON(JSON.stringify(msg));
			}
		});
	}
	//返回 刀具详细信息表格
	function formatData(data) {
		var type = data.type;
		var typeJson = data.typeJson;
		if (type == "" || typeJson == "") {
			return "暂无数据...";
		}
		var jsonDetail = $.parseJSON(typeJson);
		var str = "";
		$.each(LookUpList.data.data,
						function(i, item) {
							if (item.valueCode == type) {
								tag = $.parseJSON(item.tag);
								str += "<table  class='table table-striped table-bordered table-hover dataTables-example dataTable'>";
								var j = 0;
								$.each(tag, function(name, value) {
									$.each(jsonDetail,
											function(nameDetail,
													valueDetail) {
												if (name == nameDetail) {
													if (j % 5 == 0) {
														str += "<tr>";
													}
													str += "<td>" + value
															+ "："
															+ valueDetail
															+ "</td>";
													if ((j + 1) % 5 == 0) {
														str += "</tr>";
													}
													j++;
													return false
												}
											});
								});
								str += "</table>";
							}
						});
		return str;
	}

	function showMillTypeList(){
	    millTypeJson=LookUpList;
	    var str="<option value=''>请选择刀具直径类型</option>";
		
	    $.each(millTypeJson.data.data,function(i,item){
			if(item.typeCode=="TypeMillType"){
	        str += "<option value="+item["valueCode"]+">"+item["name"]+"</option>"
			}
	    });
	    var prow=$(str);
	    var hrow=$(str);
	    prow.appendTo('#millDNType');  
	    hrow.appendTo('#editMillDNType');  
	}
	function showLookUpList(){
	    lookUpListJson=LookUpList;
	    //console.log(millListJson.data[0]);
	    var str="<option value=''>请选择刀具类型</option>";

	    $.each(lookUpListJson.data.data,function(i,item){
			if(item.typeCode=="typesupplier"){
	    	str += "<option value="+item["valueCode"]+">"+item["name"]+"</option>"
			}
	    });
	    var prow=$(str);
	    var hrow=$(str);
	    prow.appendTo('#millType');  
	    hrow.appendTo('#editMillType');  
	}
	function selectchange(obj){
	    var tag = null;
	    var str="";
	    $.each($("#resMillForm .box-body").children(),function(i,item){
	        if(i>5){
	            $(this).remove();
	        }
	    });
	    
	    var childs = $(".box-body-add").children()
	    $.each(lookUpListJson.data.data,function(i,item){
	        if(item.valueCode==obj.value){ 
	            tag=$.parseJSON(item.tag)
 	            $.each(tag,function(name,value) {
	                str += "<div class='form-group'>"
	                str += "<label class='col-sm-3 control-label' for="+name+">"+value+":</label> ";
	                str += "<div class='col-sm-6'>";
	                str += "<input type='text' class='form-control' id="+name+" palceholder="+value+"/>";
	                str += "</div></div>";
	            });
	            var prow=$(str);
	            prow.appendTo('.box-body-add'); 
	            return false;
	        }
	    });
	}
	
</script>

